﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace GnProjectAssist
{
	public abstract class GnOption
	{

        //public delegate bool OptionAction(Object xml, bool isRead);
        public abstract class GnOptionElement
        {
            String mElementName;
            public System.String ElementName
            {
                get { return mElementName; }
            }

            protected bool mEnabled = false;
            public bool Enabled
            {
                get { return mEnabled; }
            }

            protected GnOptionElement( String elementName )
            {
                mElementName =  elementName;
            }
			public abstract bool SaveAction( XmlReader xml );
			public abstract bool LoadAction( XmlWriter xml );
        }


        static Dictionary<String, GnOption> mOptions = new Dictionary<String, GnOption>( 5 );


        Dictionary<String, GnOptionElement> mElements = new Dictionary<String, GnOptionElement>();
        public Dictionary<String, GnOptionElement> Elements
        {
            get { return mElements; }
        }

        protected bool mUseOption = true;
	    public bool UseOption
	    {
		    get { return mUseOption; }
            set { mUseOption = value; }
	    }

        private String mOptionName;
	    public System.String OptionName
	    {
            get { return mOptionName; }
	    }

		protected GnOption( String optionName )
		{
            if( String.IsNullOrEmpty( optionName ) == true )
                mOptionName = this.ToString();
            else
                mOptionName = optionName;

			AddOption( this );
			AddElement();
		}
            
		public static void LoadOption( String optionFileName )
		{
			try
			{
				XmlReader reader = XmlReader.Create( optionFileName );
				if( reader == null )
					return;

				reader.MoveToContent();
				while( reader.Read() )
				{
					switch( reader.NodeType )
					{
						case XmlNodeType.Element:
							break;
						case XmlNodeType.EndElement:
							break;
					}
				}
			}
			catch
			{
			}
		}

		void AddOption( GnOption option )
		{
			if( mOptions.ContainsKey( option.ToString() ) == true )
			{
				MessageBox.Show( "이미 존재하는 옵션 입니다 클래스 입니다.", "Wrring" );
				return;
			}
			mOptions.Add( option.OptionName, option );
		}

		protected abstract void AddElement();
        public abstract void LoadOption( XmlReader reader );
        public abstract void SaveOption( XmlReader reader );
	}
}
